package com.puny.utils
{
	import flash.geom.Point;
	
	import flexunit.framework.TestCase;

	public class InsidePointTest extends TestCase
	{
		public function InsidePointTest(methodName:String=null)
		{
			super(methodName);
		}
		
		public function testInside():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(0,0));
			assertTrue(myPoint.isInsideOf(pts));
			assertTrue(myPoint.isInsideOf(pts.reverse()));
		}

		public function testInside1():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(0,0));
			assertTrue(myPoint.isInsideOf(pts));
			assertTrue(myPoint.isInsideOf(pts.reverse()));
		}

		public function testOnEdge0():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(0,1));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		public function testOnEdge1():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(-1,0));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		public function testOnEdge2():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(0,-1));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		public function testOnEdge3():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(1,0));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		
		public function testOnVertex0():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(pts[0]);
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		public function testOnVertex1():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(pts[1]);
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		public function testOnVertex2():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(pts[2]);
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		public function testOnVertex3():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(pts[3]);
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		
		public function testNotClosed0():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 2, -1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(0,0));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		public function testNotClosed1():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 2, -1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(0,1));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		public function testNotClosed2():void {
			var pts:Array = [new Point( 1,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 2, -1)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(-1,1));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		public function testCrossed():void {
			var pts:Array = [new Point( 2,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  2)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(0,0));
			assertTrue(myPoint.isInsideOf(pts));
			assertTrue(myPoint.isInsideOf(pts.reverse()));
		}

		public function testAtCrossed():void {
			var pts:Array = [new Point( 2,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  2)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(1,1));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}

		public function testCrossedOutside():void {
			var pts:Array = [new Point( 2,  1), 
							 new Point(-1,  1),
							 new Point(-1, -1),
							 new Point( 1, -1),
							 new Point( 1,  2)];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(2,2));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
		}
		
		public function testNaNHappens():void {
			var pts:Array = [
				new Point( 308 , 272 ),
				new Point( 308 , 269 ),
				new Point( 310 , 266 ),
				new Point( 311 , 261 ),
				new Point( 314 , 257 ),
				new Point( 315 , 251 ),
				new Point( 316 , 245 ),
				new Point( 319 , 241 ),
				new Point( 320 , 232 ),
				new Point( 321 , 226 ),
				new Point( 323 , 217 ),
				new Point( 324 , 213 ),
				new Point( 324 , 208 ),
				new Point( 324 , 207 ),
				new Point( 324 , 206 ),
				new Point( 325 , 206 ),
				new Point( 325 , 206 )];
			var myPoint:InsidePointChecker = new InsidePointChecker(new Point(320,240));
			assertFalse(myPoint.isInsideOf(pts));
			assertFalse(myPoint.isInsideOf(pts.reverse()));
			
		}
	}
}